package pers.vinsonws.jianghu.clientwin.test;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import pers.vinsonws.jianghu.codeCompont.MsgEveryPro;

/**
 * @auther vinsonws
 * @date 2018/11/4 18:07
 */
public class ProtoBuftestHandler extends SimpleChannelInboundHandler<Object> {
    @Override
    protected void channelRead0(ChannelHandlerContext arg0, Object obj)
            throws Exception {
        //MsgRoom myObject=(MsgRoom)obj;
        System.out.println("client receive" + obj);
    }
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {

        for (int i=1; i<2; i++){
            ctx.write(msg(i));
            System.out.println(msg(i));
        }
        ctx.flush();
        System.out.println("发送成功");

    }

    private MsgEveryPro.Message msg(int i){
        MsgEveryPro.Message.Builder builder = MsgEveryPro.Message.newBuilder();
        builder.setUserSendId(i);
        builder.setChatRoomOrUserRecvId(i);
        builder.setDateLong(System.currentTimeMillis());
        builder.setType(1);//用户
        builder.setMessage("你好");
        return builder.build();
    }
}
